Passed
Push — master ( 6f8171...7c2bcd )
by
unknown
48s
created

WorkEnvironmentAPI.refreshWorkplacePhoto   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 1
rs 10
1
var WorkEnvironmentAPI = {};
2
WorkEnvironmentAPI.baseURL = "/tc/api/v1";
3
4
WorkEnvironmentAPI.photoNameToImgElementId = {'workplace_photo_1' : 'jobPosterWorkEnvironment_1',
5
    'workplace_photo_2' : 'jobPosterWorkEnvironment_2',
6
    'workplace_photo_3' : 'jobPosterWorkEnvironment_3'};
7
8
WorkEnvironmentAPI.defaultWorkplacePhoto = '/images/default_workplace_photo.png';
9
10
/**
11
 *
12
 * @param {string} photo_name
13
 * @param {string} description
14
 * @return {WorkEnvironment.WorkplacePhotoCaption}
15
 */
16
WorkEnvironmentAPI.WorkplacePhotoCaption = function(photo_name, description) {
17
    this.photo_name = photo_name;
18
    this.description = description;
19
};
20
21
/**
22
 *
23
 * @param {string} remote_allowed
24
 * @param {string} telework_allowed
25
 * @param {string} flexible_allowed
26
 * @param {WorkEnvironment.WorkplacePhotoCaption[]} workplace_photo_captions
27
 * @return {WorkEnvironment.WorkEnvironment}
28
 */
29
WorkEnvironmentAPI.WorkEnvironment = function(remote_allowed, telework_allowed,
30
        flexible_allowed, workplace_photo_captions) {
31
    this.remote_allowed = remote_allowed;
32
    this.telework_allowed = telework_allowed;
33
    this.flexible_allowed = flexible_allowed;
34
    this.workplace_photo_captions = workplace_photo_captions;
35
};
36
37
WorkEnvironmentAPI.parseWorkEnvironmentResponse = function(response) {
38
    console.log(response);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
39
    var json = JSON.parse(response);
40
    var workEnvironment = new WorkEnvironmentAPI.WorkEnvironment(
41
            json.basic_work_environment.remote_allowed,
42
            json.basic_work_environment.telework_allowed,
43
            json.basic_work_environment.flexible_allowed,
44
            []
45
    );
46
    for (var i=0; i<json.workplace_photo_captions.length; i++) {
47
        var caption = json.workplace_photo_captions[i];
48
        var workplacePhotoCaption = new WorkEnvironmentAPI.WorkplacePhotoCaption(
49
               caption.photo_name,
50
               caption.description
51
        );
52
        workEnvironment.workplace_photo_captions.push(workplacePhotoCaption);
53
    }
54
    return workEnvironment;
55
};
56
57
WorkEnvironmentAPI.localizeWorkEnvironment = function() {
58
    if (siteContent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable siteContent is declared in the current environment, consider using typeof siteContent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
59
        document.getElementById('jobPosterWorkEnvironmentLabel').innerHTML = siteContent.workEnvironment;
60
61
        document.getElementById('jobPosterRemoteWork_label').innerHTML = siteContent.remoteLocationAllowed;
62
        document.getElementById('jobPosterTelework_label').innerHTML = siteContent.teleworkAllowed;
63
        document.getElementById('jobPosterFlexHours_label').innerHTML = siteContent.flexHoursAllowed;
64
    }
65
};
66
67
WorkEnvironmentAPI.loadWorkEnvironmentBrowseJobs = function(managerProfileId, labelID) {
68
69
    DataAPI.getWorkplaceEnvironment(managerProfileId, function(response) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
70
        var workEnv = WorkEnvironmentAPI.parseWorkEnvironmentResponse(response);
71
        WorkEnvironmentAPI.populateWorkEnvironmentBrowseJobs(workEnv, labelID);
72
    })
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
73
74
}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
75
76
WorkEnvironmentAPI.populateWorkEnvironmentBrowseJobs = function(workEnvironment, labelID) {
77
78
    var jobCardRemote = document.getElementById(labelID);
79
80
    if (SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed) === 'Yes'){
0 ignored issues
show
Bug introduced by
The variable SliderAPI seems to be never declared. If this is a global, consider adding a /** global: SliderAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
81
        jobCardRemote.innerHTML = 'Allowed';
82
    }
83
    else if (SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed) === 'Oui') {
84
        jobCardRemote.innerHTML = 'Autorisé';
85
    }
86
    else if (SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed) === 'No') {
87
        jobCardRemote.innerHTML = 'Not Allowed';
88
    }
89
    else if (SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed) === 'Non') {
90
        jobCardRemote.innerHTML = 'Non autorisé';
91
    }
92
    else {
93
        jobCardRemote.innerHTML = 'Not Specified';
94
    }
95
96
}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
97
98
WorkEnvironmentAPI.loadWorkEnvironmentSummary = function(managerProfileId) {
99
    //Fill text fields
100
    DataAPI.getWorkplaceEnvironment(managerProfileId, function(response) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
101
        var workEnv = WorkEnvironmentAPI.parseWorkEnvironmentResponse(response);
102
        WorkEnvironmentAPI.populateWorkEnvironmentSummary(workEnv);
103
    })
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
104
    //Download photos
105
    for (photoName in WorkEnvironmentAPI.photoNameToImgElementId) {
0 ignored issues
show
Bug introduced by
The variable photoName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.photoName.
Loading history...
Coding Style introduced by
Creating global 'for' variable. Should be 'for (var photoName ...'.
Loading history...
106
        WorkEnvironmentAPI.refreshWorkplacePhoto(managerProfileId, photoName, WorkEnvironmentAPI.photoNameToImgElementId[photoName]);
107
    }
108
};
109
110
/**
111
 *
112
 * @param {WorkEnvironment.WorkEnvironment} workEnvironment
113
 * @return {undefined}
114
 */
115
WorkEnvironmentAPI.populateWorkEnvironmentSummary = function(workEnvironment) {
116
117
    document.getElementById('jobPosterRemoteWork').innerHTML = SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed);
0 ignored issues
show
Bug introduced by
The variable SliderAPI seems to be never declared. If this is a global, consider adding a /** global: SliderAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
118
    document.getElementById('jobPosterTelework').innerHTML = SliderAPI.getFrequencySliderLabel(workEnvironment.telework_allowed);
119
    document.getElementById('jobPosterFlexHours').innerHTML = SliderAPI.getFrequencySliderLabel(workEnvironment.flexible_allowed);
120
121
    for(var i=0; i<workEnvironment.workplace_photo_captions.length; i++) {
122
        var caption = workEnvironment.workplace_photo_captions[i];
123
        var imgId = WorkEnvironmentAPI.photoNameToImgElementId[caption.photo_name];
124
        if (imgId) {
125
            document.getElementById(imgId).setAttribute('title', caption.description);
126
        }
127
    }
128
129
    // TAL-150 - Remote work values for heading section
130
    if (SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed) === 'Yes'){
131
        document.getElementById('jobPosterRemoteWorkHeader').innerHTML = 'Remote Work Allowed';
132
    }
133
    else if (SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed) === 'Oui') {
134
        document.getElementById('jobPosterRemoteWorkHeader').innerHTML = 'Travail à distance autorisé';
135
    }
136
    else if (SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed) === 'No') {
137
        document.getElementById('jobPosterRemoteWorkHeader').innerHTML = 'Remote Work Not Allowed';
138
    }
139
    else if (SliderAPI.getYesNoSliderLabel(workEnvironment.remote_allowed) === 'Non') {
140
        document.getElementById('jobPosterRemoteWorkHeader').innerHTML = 'Travail à distance non autorisé';
141
    }
142
    else {
143
        document.getElementById('jobPosterRemoteWorkHeader').innerHTML = 'Remote Work Not Specified';
144
    }
145
146
};
147
148
WorkEnvironmentAPI.refreshWorkplacePhoto = function(managerProfileId, photoName, imageElementId) {
149
    var photoUrl = WorkEnvironmentAPI.baseURL+'/getWorkplacePhotoByManagerProfileAndName/'+ managerProfileId + '/' + photoName;
150
    var headers = {"Accept":"image/*"};
151
    DataAPI.sendRequest(photoUrl, "GET", headers, null, function(request) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
152
        var img = document.getElementById(imageElementId);
153
        if (request.status == 200 && request.responseURL) {
154
            img.style.backgroundImage = "url("+request.responseURL+")";
155
        } else {
156
            img.setAttribute('style','display:none;');
157
        } 
158
    });
159
};
160